from flask import Blueprint, make_response, render_template, redirect, url_for

from app.ext import mongo
from bson.objectid import ObjectId

app = Blueprint('front', __name__)

@app.route('/')
def home():
    return redirect(url_for('front.player_wall'))
    #return render_template('home.html')

@app.route('/player/<player_id>')
def player_detail(player_id):
    print player_id
    player = mongo.db.player.find_one_or_404({'_id': ObjectId(player_id)})
    #for item in mongo.db.player.find():
    #    print 'name', item['name']

    return render_template('player_detail.html', player=player)

@app.route('/photo/<id>', methods=['GET'])
def render_photo(id):
    resp = make_response(mongo.send_file(id+'.png'))
    print resp.mimetype
    return resp #mongo.send_file(id)

@app.route('/playerswall', methods=['GET'])
def player_wall():
    players = mongo.db.player.find().sort([('game_value', -1)])

    return render_template('playerwall.html', players=players)